package com.yl.applicationsecurity.controller;

import com.github.pagehelper.PageInfo;
import com.yl.applicationsecurity.pojo.Inspection;
import com.yl.applicationsecurity.pojo.InspectionConfiguration;
import com.yl.applicationsecurity.pojo.Result;
import com.yl.applicationsecurity.service.InspectionConfigurationService;
import com.yl.applicationsecurity.service.InspectionService;
import com.yl.applicationsecurity.service.ScriptStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * @author 鹤仙问鹿仙
 * @program: Application-security
 * @description:
 * @date 2025-01-08 14:22:40
 */
@RestController
@RequestMapping("/inspectionConfiguration")
public class InspectionConfigurationController {

    @Autowired
    private InspectionConfigurationService inspectionConfigurationService;
    @Autowired
    private ScriptStateService scriptStateService;


    @PostMapping("/list")
    public Result list(String[] nationSelect, InspectionConfiguration inspectionConfiguration, @RequestParam(required = false) Date[] startAndEndDate, @RequestParam(defaultValue = "1", value = "pageNum")Integer pageNum
            , @RequestParam(defaultValue = "10", value = "pageSize")Integer pageSize ){
        PageInfo< InspectionConfiguration>  InspectionConfigurationList = null;
        PageInfo<InspectionConfiguration> inspectionList = null;
        if(startAndEndDate!=null&&startAndEndDate.length!=2){
            inspectionList =  inspectionConfigurationService.findListByInspectionConfiguration(nationSelect,inspectionConfiguration,null,null,pageNum,pageSize);
        }else{
            inspectionList =  inspectionConfigurationService.findListByInspectionConfiguration(nationSelect,inspectionConfiguration,startAndEndDate[0],startAndEndDate[1],pageNum,pageSize);
        }
        return Result.success( inspectionList);
    }


    @RequestMapping("/update")
    public Result updateStatus(HttpServletRequest request, InspectionConfiguration inspectionConfiguration) {


        if(inspectionConfigurationService.updateInspectionConfiguration( inspectionConfiguration)!=0){
            return  Result.success("修改成功");
        }else{
            return  Result.error("修改失败");
        }


    }

    @RequestMapping("/updateStatus")
    public Result updateStatus(HttpServletRequest request,String[]  ids,Integer updateStatus) {


        if(inspectionConfigurationService.updateStatus(  ids, updateStatus)!=0){
            return  Result.success("修改成功");
        }else{
            return  Result.error("修改失败");
        }


    }


    @RequestMapping("/delete")
    public Result delete(HttpServletRequest request,String[]  ids,Integer updateStatus) {


        if(inspectionConfigurationService.delete(  ids)!=0){
            return  Result.success("修改成功");
        }else{
            return  Result.error("修改失败");
        }


    }



    @RequestMapping("/insert")
    public Result insert(HttpServletRequest request,InspectionConfiguration inspectionConfiguration) {
        if(inspectionConfigurationService.insert(inspectionConfiguration)!=0){
            return  Result.success("修改成功");
        }else{
            return  Result.error("修改失败");
        }


    }

    /**
     * 提供给巡检脚本的接口
     * @return
     */
    @RequestMapping("/getList")
    public Result getList() {
        //String secretKey
        List<InspectionConfiguration> list = inspectionConfigurationService.getList();
        return  Result.success(list);
    }



}

